﻿using AutoMapper;
using B.S.Traceability.Domain;
using B.S.Traceability.Error;
using B.S.Traceability.Infrastructure.Interface;
using B.S.Traceability.Writer.API.Application.Commends.Imgs;
using MediatR;

namespace B.S.Traceability.Writer.API.Application.CommendHandlers.Imgs
{
    public class QueryInspecCommendHandlers:IRequestHandler<QueryInspecCommends,APIResult<IntegrateImgs>>
    {

        private readonly IBaseRepository<IntegrateImgs> integrateRepository;
        private readonly IMapper mapper;

        public QueryInspecCommendHandlers(IBaseRepository<IntegrateImgs> integrateRepository, IMapper mapper)
        {
            this.integrateRepository = integrateRepository;
            this.mapper = mapper;
        }



        /// <summary>
        /// 添加检验单
        /// </summary>
        /// <param name="request"></param>
        /// <param name="cancellationToken"></param>
        /// <returns></returns>
        /// <exception cref="NotImplementedException"></exception>
        public async Task<APIResult<IntegrateImgs>> Handle(QueryInspecCommends request, CancellationToken cancellationToken)
        {
            APIResult<IntegrateImgs> result = new APIResult<IntegrateImgs>();
            result.Code = APIEnum.添加成功;
            result.Msg= "添加成功";

            var integrateImgs =mapper.Map<IntegrateImgs>(request);

            integrateImgs.BatchId = request.BatchId;
            integrateImgs.ImgType = request.ImgType;
            integrateImgs.ImgName = request.ImgName;
           await  integrateRepository.Add(integrateImgs);

            
            return await  Task.FromResult(result);


        }
    }
}
